package com.sls.web.manager.action.game;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.execption.ManagerException;
import com.sls.web.manager.game.pojo.XinHeProduct;
import com.sls.web.manager.game.pojo.XinHeRespInfo;
import com.sls.web.manager.game.service.XinHeService;
import com.sls.web.manager.page.Pagination;

public class XinHeAction extends SuperAction {

	private static final long serialVersionUID = 4095554890062214990L;
	@Resource(name = "xinheService")
	private XinHeService xinHeService;

	private XinHeProduct xinHeProduct;
	private XinHeProduct xinHeQuery;
	private Pagination<?> page;
	private String id;
	private String productId;
	private String productName;
	private XinHeRespInfo respInfo;
	private String merchantId;
	private String orderId;

	public String add() {
		return INPUT;
	}

	/**
	 * 列表展示
	 * 
	 * @return
	 */
	public String list() {
		if (xinHeQuery == null) {
			xinHeQuery = new XinHeProduct();
			xinHeQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
			xinHeQuery.setPageSize(Constants.INIT_PAGESIZE);
		}
		try {
			page = this.xinHeService.queryXHProPagination(xinHeQuery,
					getCurrentOperator());
		} catch (ManagerException e) {
			this.addActionError(e.getMessage());
		}
		return "list";
	}

	public String toEdit() {
		try {
			xinHeProduct = this.xinHeService.queryXHProductById(id,
					getCurrentOperator());
		} catch (ManagerException e) {
			this.addActionError(e.getMessage());
		}
		return INPUT;
	}

	public String edit() {
		try {
			this.xinHeService.update(xinHeProduct, getCurrentOperator());
			if (xinHeQuery == null) {
				xinHeQuery = new XinHeProduct();
				xinHeQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
				xinHeQuery.setPageSize(Constants.INIT_PAGESIZE);
			}
			if (StringUtils.isNotEmpty(productId)) {
				xinHeQuery.setProductId(productId);
			}
			if (StringUtils.isNotEmpty(productName)) {
				xinHeQuery.setProductName(productName);
			}
		} catch (ManagerException e) {
			this.addActionError(e.getMessage());
		}
		return list();
	}

	public String sync() {
		try {
			this.xinHeService.saveSyncInfo(getCurrentOperator());
			this.redirectionUrl = "xin_he!list.htm";
		} catch (ManagerException e) {
			this.addActionError(e.getMessage());
		}
		return SUCCESS;
	}

	/**
	 * 批量上架
	 * 
	 * @return
	 * @throws Exception
	 */
	public String batchOnline() throws Exception {
		try {
			this.xinHeService.batchOnline("1", getCurrentOperator());
			redirectionUrl = "xin_he!list.htm";
		} catch (ManagerException e) {
			flag = false;
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}

	/**
	 * 批量下架
	 * 
	 * @return
	 * @throws Exception
	 */
	public String batchOffline() throws Exception {
		try {
			this.xinHeService.batchOffline("0", getCurrentOperator());
			redirectionUrl = "xin_he!list.htm";
		} catch (ManagerException e) {
			flag = false;
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}

	public String toQueryOrder() {
		return "order";
	}

	public String queryOrder() {
		try {
			respInfo = this.xinHeService.queryOrder(orderId,
					getCurrentOperator());
			respInfo.setOrderNo(orderId);
			respInfo.setUserId(merchantId);
		} catch (ManagerException e) {
			this.addActionError(e.getMessage());
		}
		return "order";
	}

	public XinHeProduct getXinHeProduct() {
		return xinHeProduct;
	}

	public void setXinHeProduct(XinHeProduct xinHeProduct) {
		this.xinHeProduct = xinHeProduct;
	}

	public XinHeProduct getXinHeQuery() {
		return xinHeQuery;
	}

	public void setXinHeQuery(XinHeProduct xinHeQuery) {
		this.xinHeQuery = xinHeQuery;
	}

	public Pagination<?> getPage() {
		return page;
	}

	public void setPage(Pagination<?> page) {
		this.page = page;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public XinHeRespInfo getRespInfo() {
		return respInfo;
	}

	public void setRespInfo(XinHeRespInfo respInfo) {
		this.respInfo = respInfo;
	}

	public String getMerchantId() {
		return merchantId;
	}

	public void setMerchantId(String merchantId) {
		this.merchantId = merchantId;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

}
